//节点相关函数
export default function nodeFn(x6BaseGraph) {

    var main = x6BaseGraph;
    var objFn = {

        //获取所有节点
        getNodes() {
            return main.getNodes();
        },
        //返回 根节点
        getRootNode() {
            let node = main.getRootNodes();
            node = node instanceof Array ? node[0] : node
            return node;
        },
        //根据id找对象
        getById(id) {
            let cell = main.getCellById(id)
            return cell;
        },
        //返回当前节点的所有子节点/边
        getChildrenList() {

        },
        //处理隐藏的节点
        nodeIsShowFn() {
            let obj = {
                "up": [],
                "down": []
            };
            let nodes = main.getNodes()

            nodes.map((node) => {
                if (!node.data.showFlag && node.data.dir) {
                    obj[node.data.dir].push(node.id);
                    node.hide();
                }
            })
            return obj;
        },
        //返回所有节点初始化需要的属性
        getNodesInited() {
            let nodes = []
            let keys = ["attrs", "children", "data", "label", "markup", "model", "parent", "portContainerMarkup", "portLabelMarkup", "portMarkup", "ports", "shape", "view", "visible", "zIndex", "Symbol", "Symbol(Symbol.toStringTag)", ]
            main.getNodes().map((item, index) => {
                let obj = {}
                for (const key in item) {
                    const element = item[key];
                    obj[key] = element;
                }
                let obj2 = {}
                keys.map(it => {
                    obj2[it] = item[it]
                })
                nodes.push({
                    ...obj,
                    ...obj2
                })
            })
            return nodes;
        }

    }

    return objFn;
}